package chaoyue.study.servlet;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 响应302重定向码，让浏览器进行跳转
 */
public class Test1_Socket2 {
    public static void main(String[] args) throws IOException {
        // 创建一个服务器监听在8080端口
        ServerSocket serverSocket = new ServerSocket(8080);
        Socket server = serverSocket.accept();

        OutputStream outputStream = server.getOutputStream();
        // 按照http协议的格式封装一个可以重定向的报文
        String response = "HTTP/1.1 302 Moved Temporarily\r\n" +
                "Location: https://bilibili.com\r\n\r\n";
        // 将报文写出给浏览器
        outputStream.write(response.getBytes());
        outputStream.flush();
    }
}
